<?php defined('In33hao') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title"><a class="back" href="index.php?act=hao&op=diymenu" title="返回微信菜单"><i class="fa fa-arrow-circle-o-left"></i></a>
      <div class="subject">
        <h3><?php echo $lang['diymenu'];?> - 新增下级</h3>
        <h5>你可以在这里添加微信子菜单</h5>
      </div>
    </div>
  </div>
  <form id="diymenu_form" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <div class="ncap-form-default">
      <dl class="row">
        <dt class="tit">
          <label for="title"><em>*</em>子菜单名称</label>
        </dt>
        <dd class="opt">
          <input type="text" value="" name="title" id="title" maxlength="20" class="input-txt">
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="pid"><em>*</em>上级分类</label>
        </dt>
        <dd class="opt">
          <select name="pid" id="pid">
            <option value="0"><?php echo $lang['nc_please_choose'];?></option>
            <?php if(!empty($output['parent_list']) && is_array($output['parent_list'])){ ?>
            <?php foreach($output['parent_list'] as $k => $v){ ?>
            <option <?php if($output['pid'] == $v['id']){ ?>selected='selected'<?php } ?> value="<?php echo $v['id'];?>"><?php echo $v['title'];?></option>
            <?php } ?>
            <?php } ?>
          </select>
          <span class="err"></span>
          <p class="notic">每个顶级菜单只能添加5个子菜单</p>
        </dd>
      </dl>
        <dl class="row">
            <dt class="tit">
                <label for="url">url链接</label>
            </dt>
            <dd class="opt">
                <input type="text" value="" name="url" id="url" maxlength="255" class="input-txt">
                <span class="err"></span>
                <p>
                    从功能库选择：
                    <select name="fun" id="fun">
                        <option value="">自定义链接</option>
                        <?php if(!empty($output['module']) && is_array($output['module'])){ ?>
                            <?php foreach($output['module'] as $k => $v){ ?>
                                <option  value="<?php echo $v['url'];?>"><?php echo $v['title'];?></option>
                            <?php } ?>
                        <?php } ?>
                    </select>
                </p>
                <p class="notic">必须是以http://打头的完整链接</p>
            </dd>
        </dl>
        <dl class="row">
            <dt class="tit">
                <label for="keyword">关键字</label>
            </dt>
            <dd class="opt">
                <input type="text" value="" name="keyword" id="keyword" maxlength="20" class="input-txt">
                <span class="err"></span>
                <p class="notic"></p>
            </dd>
        </dl>
      <dl class="row">
        <dt class="tit">
          <label><?php echo $lang['nc_sort'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" value="0" name="sort" id="sort" class="input-txt">
          <span class="err"></span>
          <p class="notic">数字范围为0~255，数字越小越靠前</p>
        </dd>
      </dl>
        <dl class="row">
            <dt class="tit">显示状态</dt>
            <dd class="opt">
                <div class="onoff">
                    <label for="brand_recommend1" class="cb-enable "><?php echo $lang['nc_yes'];?></label>
                    <label for="brand_recommend0" class="cb-disable selected"><?php echo $lang['nc_no'];?></label>
                    <input id="brand_recommend1" name="is_show"   value="1" type="radio">
                    <input id="brand_recommend0" name="is_show" value="0" type="radio">
                </div>
                <p class="notic"><?php echo $lang['brand_index_recommend_tips'];?></p>
            </dd>
        </dl>
      <div class="bot"><a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" id="submitBtn"><?php echo $lang['nc_submit'];?></a></div>
    </div>
  </form>
</div>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/common_select.js" charset="utf-8"></script>
<script>
$(function(){
//自动加载滚动条
    $('#type_div').perfectScrollbar();
//按钮先执行验证再提交表单    
	$("#submitBtn").click(function(){
		if($("#diymenu_form").valid()){
			$("#diymenu_form").submit();
		}
	});
//表单验证
	$('#diymenu_form').validate({
        errorPlacement: function(error, element){
			var error_td = element.parent('dd').children('span.err');
            error_td.append(error);
        },
        rules : {
            title : {
                required : true,
                remote   : {                
                url :'index.php?act=hao&op=diymenu_ajax',
                type:'get',
                data:{
                    title : function(){
                        return $('#title').val();
                    },
                    pid : function() {
                        return $('#pid').val();
                    },
                  }
                }
            },
            url : {
                required   : true
            },

            sort : {
                number   : true
            }
        },
        messages : {
            title : {
                required : '<i class="fa fa-exclamation-circle"></i>菜单名称必须填写',
                remote   : '<i class="fa fa-exclamation-circle"></i>该名称已存在'
            },
            url : {
                required   : '<i class="fa fa-exclamation-circle"></i>url链接必须填写'
            },
            sort  : {
                number   : '<i class="fa fa-exclamation-circle"></i>排序必须为数字'
            }
        }
    });
});

    $("#fun").change(function(){
        var url = $(this).val();
        $("#url").val(url);
    });
</script>
